package com.lkl.hystrixdemo.order.zookeeper.order;

import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderUtils implements Runnable {

    private int num = 1;


    /**
     * 加同步才会不变
     * @return
     */
    private synchronized String getOrder() {
        String format = "YYYY-MM-dd-hh-mm-ss";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        ++num;
        return simpleDateFormat.format(new Date()) + "-" + num;
    }

    @Override
    public void run() {
        String order = getOrder();
        System.out.println(Thread.currentThread().getName() + ",获取的订单号," + order);
    }

    public static void main(String[] args) {
        OrderUtils orderUtils = new OrderUtils();
        for (int i = 0; i < 1000; i++) {
            new Thread(orderUtils).start();
        }
    }
}
